home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.Stanford.EDU!microunity!toms
- From: toms@MicroUnity.com (Tom Sanders)
- Subject: Re: Floating point calculation order
- Message-ID: <DLnE5K.2xH@microunity.com>
- Sender: usenet@microunity.com (news id)
- Organization: MicroUnity Systems Engineering, Inc.
- References: <m0tedv8-0002eqC@sice.nsk.su> <3104c6d9.134061184@nntp.ix.netcom.com>
- Date: Tue, 23 Jan 1996 19:00:56 GMT
-
- In article <3104c6d9.134061184@nntp.ix.netcom.com>, miker3@ix.netcom.com (Mike Rubenstein) writes:
- |> "Pavel A. Zemtsov" <PZEM@sice.nsk.su> wrote:
- |>
- |> >
- |> > Having declaration
- |> >
- |> > double x, p, q, r;
- |> >
- |> > my compiler (cc on SCO 3.2) calculated following expression:
- |> >
- |> > x = p * q / r;
- |> >
- |> > as p * (q/r); (I mean, it divided first, than multiplied). That
- |> > resulted in precision loss.
- |> >
- |> > Is this legal behavior?
- |>
- |> Not in ANSI C, but it was legal in K&R. If memory serves, it was not
- |> made illegal until very late in the standardizattion process so if
- |> your compiler was written before the standard was finalized it may not
- |> adhere to this.
- |>
- |> Michael M Rubenstein
-
- I am a firm believer in not allowing a compiler to make these decisions for
- me. It's best to specify with parens the order of evaluation and not leave
- it up to the compiler defaults. I would actually prefer a compiler that
- gave a warning if I did have an equation that could be evaluated in more
- than 1 order (something I have not done in over 20 years).
-
- My opion of course,
- Tom Sanders
-